package com.mfnote.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.mfnote.db.dao.HandDao;
import com.mfnote.view.R;

public class HandAdapter extends BaseAdapter{
	private HandDao handDao =null;
	private ArrayList<HashMap<String, Object>> list = null;
	private HashMap<String,Object> map = null;
	
	private LayoutInflater inflater = null;
	
	private ImageView hand_list_item_imageView = null;
	private TextView hand_lv_title = null;
	private TextView hand_lv_time = null;
	
	private View view = null;
	public HandAdapter(Context context){
		inflater = LayoutInflater.from(context);
		handDao = new HandDao(context);
		list = handDao.getHandAllCount();
	}
    
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		map = list.get(position);
		if(convertView==null){
			view =  inflater.inflate(R.layout.hand_listview_item, null);
		}else{
			view = convertView;
		}
		hand_list_item_imageView = (ImageView) view.findViewById(R.id.hand_list_item_imageView);
		hand_lv_title = (TextView) view.findViewById(R.id.hand_lv_title);
		hand_lv_time = (TextView) view.findViewById(R.id.hand_lv_time);
		
		hand_lv_title.setText(map.get("title").toString());
		hand_lv_time.setText(map.get("time").toString());
		String imagePath= map.get("imagePath").toString();
		Log.d("imagePath_", "----"+imagePath);
		int flag = (Integer) map.get("flag");
		Log.d("flag", "============"+flag);
		if(flag==0){
			if("0".equals(imagePath)){
				//圆
				hand_list_item_imageView.setImageResource(R.drawable.shortcut_handdraw);
			}
			if("1".equals(imagePath)){
				hand_list_item_imageView.setImageResource(R.drawable.shortcut_handdraw);
			}
			if("2".equals(imagePath)){
				hand_list_item_imageView.setImageResource(R.drawable.shortcut_handdraw);
			}
			if("3".equals(imagePath)){
				hand_list_item_imageView.setImageResource(R.drawable.shortcut_handdraw);
			}
			if("4".equals(imagePath)){
				hand_list_item_imageView.setImageResource(R.drawable.shortcut_handdraw);
			}
			if("5".equals(imagePath)){
				hand_list_item_imageView.setImageResource(R.drawable.shortcut_handdraw);
			}
			if("6".equals(imagePath)){
				hand_list_item_imageView.setImageResource(R.drawable.shortcut_handdraw);
			}
		}else if(flag==1){
			if(imagePath.contains("png")){
				//说明是手写的item
				hand_list_item_imageView.setImageResource(R.drawable.shortcut_hand);
			}
		}
		return view;
	}

}
